var heatmap = {
    map: null,
    vector: null,
    source: null,
    rqVector: null,
    rqSource: null,
    rqInfoSource: null,
    selectPointerMove: null,
    isRqInfo: null,
    inputData: null,
    overly: null,
    rqInfoVector: null,
    zoneNumber: null,
    rqInfoId: null,
    rqInfoCount: null,
    rqInfoName: null,
    mousePosition: null,
    boundFeat: null,
    clickFeature: null,
    selectStyle: null,
    selectFeature: null,
    isClick: null,
    heatMapInit:function(){
        this.map = xdmap.mapInit('allmap', 4, [12122301.189802673,4070118.8821290657]);
        this.map.getView().setMaxZoom(18);
        this.map.getView().setMinZoom(4);
        this.map.getView().setZoom(5);
    },
    getHeatMap: function (inputData, blur, radius) {
        this.inputData = inputData;
        this.map.on('pointermove', function (evt) {
            heatmap.mousePosition = evt.coordinate;
        });
        this.map.on('singleclick',function(e){
            console.log(e.coordinate);
        })
        this.selectPointerMove = new ol.interaction.Select({
            condition: ol.events.condition.pointerMove
        });
        this.selectPointerMove.on('select', function (e) {
            heatmap.onPointerMove(e);
        });
        this.map.on('singleclick', function (e) {
            heatmap.onPointerClick(e);
        });
        this.map.getView().on('change:resolution', function (e) {
            heatmap.onResChange(e, inputData.city);
        });
        heatmap.getArea();
        var style = function (feature, resolution) {
            if (feature == null) {
                return;
            }
            var type = feature.getGeometry().getType();
            var style = feature.getStyle();
            var text = null;
            if (typeof feature.getProperties().text === 'undefined') {
                text = 'none';
            } else {
                var text = feature.getProperties().text
            }
            feature.setStyle(heatmap.getUnselectedPropertyStyle(type, text, style, feature));
        }
        this.rqVector = new ol.layer.Vector({
            style: style
        });
        this.rqVector.setVisible(false);
        this.map.addLayer(this.rqVector);
        this.source = this.getSource(inputData);
        this.vector = new ol.layer.Heatmap({
            source: this.source,
            blur: 15/*parseInt(blur.value, 10)*/,
            radius: 8/*parseInt(radius.value, 10)*/,
            opacity: 0.6
        });
        blur.addEventListener('input', function () {
            heatmap.vector.setBlur(parseInt(blur.value, 10));
        });
        radius.addEventListener('input', function () {
            heatmap.vector.setRadius(parseInt(radius.value, 10));
        });
        this.map.addLayer(this.vector);
    },
    getSource: function (inputData) {
        $.ajaxSettings.async = false;
        var features = new Array();
        var ep3 = new ol.proj.Projection({
            code: 'EPSG:3857'
        });
        var ep4 = new ol.proj.Projection({
            code: 'EPSG:4326'
        });
        var url = "/map/initHeatMapData";
        $.getJSON(url, inputData, function (data) {
            if(heatmap.source != null){
                heatmap.source.clear();
            }
            var result = data.result.mapDataList;
            result.forEach(function (val) {
                var point = [val.lng, val.lat];
                var feature = new ol.Feature({
                    id: val.communityId,
                    zoneNumber: val.zoneNumber,
                    geometry: new ol.geom.Point(point)
                })
                features.push(feature);
            })
            heatmap.source = new ol.source.Vector({
                features: features
            })
            heatmap.source.set('type', 'heat', false);
            //heatmap.getArea();
        });
        return heatmap.source;
        $.ajaxSettings.async = true;
    },
    getRqSource: function (inputData) {
        var url = '/map/initHeatMapData';
        var source = new ol.source.Vector({
            format: new ol.format.GeoJSON({
                defaultDataProjection: 'EPSG:4326',
                featureProjection: 'EPSG:3857'
            }),
            loader: function (extent, resolution, projection) {
                $.ajax({
                    url: url,
                    type: 'POST',
                    async: true,
                    data: inputData,
                    success: function (data) {
                        var list = data.result.mapDataList;
                        var zoom = heatmap.map.getView().getZoom();
                        var radius = 1e6 / Math.pow(2, zoom - 2.35);
                        list.forEach(function (item) {
                            if (item.communityname != null) {
                                var text = xdmap.tool.strWrap(item.communityname.replace(/\s/g, ""), 4);
                                var center = [item.lng, item.lat];
                                var feature = new ol.Feature({
                                    id: item.communityid,
                                    zoneNumber: item.zonenumber,
                                    warningTypes: item.type,
                                    geometry: new ol.geom.Circle(center, radius),
                                    text: text + '\n' + item.count + '笔'
                                });
                                feature.set('name', item.communityname.replace(/\s/g, ""), false);
                                feature.set('count', item.count, false);
                                feature.set('type', 'rq', false);
                                source.addFeature(feature);
                            }
                        })
                        this.rqSource = source;
                    }
                })
            }
        })
        source.set('type', 'rq', false);
        heatmap.rqSource = source;
        return source;
    },
    getRqInfoSource: function () {
        var url = '/map/mapCommunityBuildingData';
        var source = new ol.source.Vector({
            format: new ol.format.GeoJSON({
                defaultDataProjection: 'EPSG:4326',
                featureProjection: 'EPSG:3857'
            }),
            loader: function (extent, resolution, projection) {
                var inputData = heatmap.getInputData('heatMap');
                inputData.communityId = heatmap.rqInfoId;
                inputData.city = heatmap.zoneNumber;
                $.ajax({
                    url: url,
                    type: 'POST',
                    async: true,
                    data: inputData,
                    success: function (data) {
                        if (data.result.community == null) {
                            return;
                        }
                        if(heatmap.map.getView().getZoom() <18){
                            return;
                        }
                        var points = new Array();
                        var resultPoints = new Array()
                        var strPoint = $.trim(data.result.community.bound.slice(7).replace('((', '').replace('))', ''));
                        var point = strPoint.split(',');
                        point.forEach(function (point) {
                            var arrPoint = $.trim(point).split(' ');
                            var newArr = ol.proj.transform(arrPoint, 'EPSG:3857', 'EPSG:4326')
                            points.push(newArr);
                        })
                        resultPoints.push(points);
                        var jsonFeature = {
                            'type': 'Feature',
                            'geometry': {
                                'type': 'Polygon',
                                'coordinates': resultPoints
                            }
                        }
                        heatmap.boundFeat = source.getFormat().readFeature(jsonFeature);
                        heatmap.boundFeat.setStyle(new ol.style.Style({
                            stroke: new ol.style.Stroke({
                                color: 'rgba(250,176,117,1)',
                                width: 2
                            }),
                            fill: new ol.style.Fill({
                                color: 'rgba(255,179,91,0.2)'
                            })
                        }))
                        heatmap.boundFeat.set('info', 'rqBound');
                        source.addFeature(heatmap.boundFeat); //小区边界
                        //小区中心
                        var communityName = data.result.community.communityName;
                        var hourseCount = data.result.community.totalHouseHoldCount;
                        var div = heatmap.createRightDiv(communityName, hourseCount);
                        var centerOverly = new ol.Overlay({
                            element: div,
                            position: [data.result.community.arcgisX, data.result.community.arcgisY],
                            offset: [-10, -30],
                            autoPan: true,
                            autoPanAnimation: {
                                duration: 250
                            }
                        })
                        heatmap.map.addOverlay(centerOverly);
                        var warningType = inputData.warningType;
                        if( !warningType || warningType == '1' || warningType == '14'){
                            //小区楼栋
                            var divList = heatmap.createDiv(data.result.mapDataList);
                            divList.forEach(function (item) {
                                var div = item[0];
                                //var point = ol.proj.transform(item[1], 'EPSG:4326', 'EPSG:3857');
                                var point = item[1];
                                var overly = new ol.Overlay({
                                    element: div,
                                    position: point,
                                    offset: [-10, -30],
                                    autoPan: true,
                                    autoPanAnimation: {
                                        duration: 250
                                    }
                                })
                                heatmap.map.addOverlay(overly);

                            })
                        }
                        heatmap.showOverly();
                    }
                })
            }
        })
        source.set('id', 'rqInfo');
        this.rqInfoSource = source;
        return source;
    },
    getRqInfoSourceForExtent: function () {
        var source = new ol.source.Vector({
            format: new ol.format.GeoJSON({
                defaultDataProjection: 'EPSG:4326',
                featureProjection: 'EPSG:3857'
            }),
            loader: function (extent, resolution, projection) {
                var resultFeature = null;
                if (heatmap.clickFeature != null) {
                    resultFeature = heatmap.clickFeature;
                    heatmap.clickFeature = null;
                } else {
                    resultFeature = heatmap.getResultFeature();
                }
                if (resultFeature == null) {
                    return;
                }
                var id = resultFeature.get('id');
                var zoneNumber = resultFeature.get('zoneNumber');
                var warningTypes = resultFeature.get('warningTypes').split(',');
                heatmap.inputData.warningType = warningTypes[0];
                heatmap.rqInfoId = id;
                heatmap.zoneNumber = zoneNumber;
                heatmap.rqInfoCount = resultFeature.get('count');
                heatmap.rqInfoName = resultFeature.get('name');
                var inputData = heatmap.inputData;
                inputData.communityId = id;
                inputData.city = zoneNumber;
                $.ajax({
                    url: '/map/mapCommunityBuildingData',
                    type: 'POST',
                    async: true,
                    data: inputData,
                    success: function (data) {
                        if (data.result.community == null) {
                            return;
                        }
                        if(heatmap.map.getView().getZoom() <18){
                            return;
                        }
                        var points = new Array();
                        var resultPoints = new Array()
                        var strPoint = $.trim(data.result.community.bound.slice(7).replace('((', '').replace('))', ''));
                        var point = strPoint.split(',');
                        point.forEach(function (point) {
                            var arrPoint = $.trim(point).split(' ');
                            var newArr = ol.proj.transform(arrPoint, 'EPSG:3857', 'EPSG:4326')
                            points.push(newArr);
                        })
                        resultPoints.push(points);
                        var jsonFeature = {
                            'type': 'Feature',
                            'geometry': {
                                'type': 'Polygon',
                                'coordinates': resultPoints
                            }
                        }
                        heatmap.boundFeat = source.getFormat().readFeature(jsonFeature);
                        heatmap.boundFeat.setStyle(new ol.style.Style({
                            stroke: new ol.style.Stroke({
                                color: 'rgba(250,176,117,1)',
                                width: 2
                            }),
                            fill: new ol.style.Fill({
                                color: 'rgba(255,179,91,0.2)'
                            })
                        }))
                        heatmap.boundFeat.set('info', 'rqBound');
                        source.addFeature(heatmap.boundFeat); //小区边界
                        var communityName = data.result.community.communityName;
                        var hourseCount = data.result.community.totalHouseHoldCount;
                        heatmap.map.getOverlays().clear();
                        var center = [data.result.community.arcgisX, data.result.community.arcgisY];
                        var div = heatmap.createRightDiv(communityName, hourseCount);
                        var id = Date.parse(new Date());
                        var centerOverly = new ol.Overlay({
                            id: id,
                            element: div,
                            position: [data.result.community.arcgisX, data.result.community.arcgisY],
                            offset: [-10, -30],
                            autoPan: true,
                            autoPanAnimation: {
                                duration: 250
                            }
                        })
                        heatmap.map.addOverlay(centerOverly);
                        var warningType = inputData.warningType;
                        if( !warningType || warningType == '1' || warningType == '14'){
                            //小区楼栋
                            var divList = heatmap.createDiv(data.result.mapDataList);
                            divList.forEach(function (item) {
                                var div = item[0];
                                //var point = ol.proj.transform(item[1], 'EPSG:4326', 'EPSG:3857');
                                var point = item[1];
                                var overly = new ol.Overlay({
                                    element: div,
                                    position: point,
                                    offset: [-10, -30],
                                    autoPan: true,
                                    autoPanAnimation: {
                                        duration: 250
                                    }
                                })
                                heatmap.map.addOverlay(overly);

                            })
                        }
                        heatmap.showOverly();
                    }
                });
            }
        })
        source.set('id', 'rqInfo');
        this.rqInfoSource = source;
        return source;
    },
    getResultFeature: function () {
        var resultFeature = null;
        if (heatmap.rqSource == null) {
            heatmap.rqSource = new ol.source.Vector();
            $.ajax({
                url: '/map/mapCommunityData',
                type: 'POST',
                async: false,
                data: heatmap.inputData,
                success: function (data) {
                    var list = data.result.mapDataList;
                    var zoom = heatmap.map.getView().getZoom();
                    var radius = 1e6 / Math.pow(2, zoom - 2.3);
                    list.forEach(function (item) {
                        var center = [item.lng, item.lat];
                        var feature = new ol.Feature({
                            id: item.communityId,
                            zoneNumber: item.zoneNumber,
                            geometry: new ol.geom.Circle(center, radius),
                            text: item.communityName.replace(/\s/g, "") + '\n' + item.count + '笔'
                        });
                        feature.set('name', item.communityName.replace(/\s/g, ""), false);
                        feature.set('count', item.count, false);
                        feature.set('type', 'rq', false);
                        heatmap.rqSource.addFeature(feature);
                    })
                }
            })
        }
        var ext = heatmap.map.getView().calculateExtent();
        var resultFeatures = heatmap.rqSource.getFeaturesInExtent(ext);
        var minDistance = 0;
        resultFeatures.forEach(function (feature) {
            var point = feature.getGeometry().getCenter();
            var distance = new ol.Sphere(6378137).haversineDistance(point, heatmap.mousePosition);
            if (minDistance == 0) {
                minDistance = distance;
                resultFeature = feature;
            } else {
                if (distance < minDistance) {
                    minDistance = distance;
                    resultFeature = feature;
                }
            }
        })
        return resultFeature;
    },
    onPointerClick: function (e) {
        var pixel = heatmap.map.getEventPixel(e.originalEvent);
        var feature = heatmap.map.forEachFeatureAtPixel(pixel, function (feature, layer) {
            return feature;
        });
        if (feature == null) {
            return;
        } else {
            heatmap.clickFeature = feature;
            heatmap.selectFeature = feature;
            heatmap.selectStyle = feature.getStyle();
            var type = feature.getGeometry().getType();
            var ty = feature.get('type');
            if (type == 'Circle') {
                if (ty == 'rq') {
                    var style = new ol.style.Style({
                        stroke: new ol.style.Stroke({
                            color: 'rgba(1, 1, 1,0)',
                            width: 0
                        })
                    })
                    feature.setStyle(style);
                    heatmap.rqInfoId = feature.N.id;
                    heatmap.zoneNumber = feature.N.zoneNumber;
                    heatmap.rqInfoCount = feature.get('count');
                    var warningTypes = feature.N.warningTypes.split(',');
                    heatmap.inputData.warningType = warningTypes[0];
                    var center = feature.getGeometry().getCenter();
                    heatmap.map.getView().setCenter(center);
                    heatmap.map.getView().setZoom(18);
                }
            } else {
                return;
            }
        }
    },
    onPointerMove: function (e) {
        var feature = e.selected[0];
        if (feature == null) {
            heatmap.rqVector.getSource().getFeatures().forEach(function (feature) {
                var type = feature.getGeometry().getType();
                var text = feature.getProperties().text;
                var style = feature.getStyle();
                feature.setStyle(heatmap.getUnselectedPropertyStyle(type, text, style, feature));
            })
            return;
        } else {
            var type = feature.getGeometry().getType();
            if (type == 'Circle') {
                var text = feature.getProperties().text;
                feature.setStyle(heatmap.getSelectedPropertyStyle(type, text));
            }
        }
    },
    onResChange: function (e) {
        var zoom = heatmap.map.getView().getZoom();
        if(zoom >= 5 && zoom <16){
            $('.clusterImg').hide()
            $('.heatImg').show();
            $('.housingImg').hide();
        }
        if(zoom >=16 && zoom <18){
            $('.clusterImg').show()
            $('.heatImg').hide();
            $('.housingImg').hide();
        }
        if(zoom >= 18){
            $('.clusterImg').hide()
            $('.heatImg').hide();
            $('.housingImg').show();
        }
        if (zoom < 16) {
            if (!heatmap.vector.getVisible()) {
                heatmap.isRqInfo = false;
                heatmap.vector.setVisible(true);
                heatmap.rqVector.setVisible(false);
                heatmap.map.removeInteraction(heatmap.selectPointerMove);
            }
        } else if (zoom >= 16 && zoom < 18) {
            heatmap.map.getOverlays().clear();
            heatmap.rqVector.setVisible(true);
            heatmap.vector.setVisible(false);
            if (heatmap.selectFeature != null) {
                heatmap.selectFeature.setStyle(heatmap.selectStyle);
                heatmap.selectFeature = null;
                heatmap.selectStyle = null;
            }
            if (heatmap.rqSource != null) {
                heatmap.rqVector.setSource(heatmap.rqSource)
            } else {
                var inputData = heatmap.inputData;
                heatmap.rqVector.setSource(heatmap.getRqSource(inputData))
            }
            if (heatmap.boundFeat != null) {
                heatmap.removeFeature(heatmap.rqInfoVector)
            }
            heatmap.map.addInteraction(heatmap.selectPointerMove);
            heatmap.setCircle(zoom);
        } else if (zoom == 18) {
            heatmap.map.getOverlays().clear();
            heatmap.vector.setVisible(false);
            heatmap.rqVector.setVisible(false);
            if (heatmap.rqInfoVector != null) {
                heatmap.map.removeLayer(heatmap.rqInfoVector);
            }
            heatmap.rqVector.setSource(new ol.source.Vector());
            heatmap.rqInfoVector = new ol.layer.Vector();
            if (heatmap.isClick) {
                heatmap.isClick = false;
                heatmap.rqInfoVector.setSource(heatmap.getRqInfoSource())
                heatmap.map.addLayer(heatmap.rqInfoVector);
            } else {
                heatmap.rqInfoVector.setSource(heatmap.getRqInfoSourceForExtent())
                heatmap.map.addLayer(heatmap.rqInfoVector);
            }
            heatmap.map.addInteraction(heatmap.selectPointerMove);
        }
    },
    setCircle: function (zoom) {
        if (this.rqVector.getSource() != null) {
            this.rqVector.getSource().forEachFeature(function (feature) {
                var geo = feature.getGeometry();
                if (geo.getType() == 'Circle') {
                    geo.setRadius(1e6 / Math.pow(2, zoom - 2.35));
                }
            })
        }
    },
    getSelectedPropertyStyle: function (type, text) {
        var style = null;
        if (type == 'Circle') {
            style = new ol.style.Style({
                fill: new ol.style.Fill({
                    color: 'rgba(226, 74, 76, 1)',
                    opacity: '0.05'
                }),
                text: new ol.style.Text({
                    font: '10px',
                    textAlign: 'center',
                    rotateWithView: true,
                    text: text,
                    fill: new ol.style.Fill({
                        color: '#FFFFFF'
                    })
                })
            })
        }
        if (type == 'MultiPolygon' || type == 'Polygon') {
            style = new ol.style.Style({
                stroke: new ol.style.Stroke({
                    color: 'green',
                    width: 2
                }),
                fill: new ol.style.Fill({
                    color: 'rgba(76, 160, 101, 0.5)'
                })
            })
        }
        return style;
    },
    getUnselectedPropertyStyle: function (type, text, Style, feat) {
        var style = null;
        if (type == 'Point') { // 如果是点, 不去设置他的样式
            style = Style;
        }
        if (type == 'Circle') {
            var id = 'rq';
            var size = feat.get('count');
            var color = heatmap.getColorForId(id, size);
            style = new ol.style.Style({
                fill: new ol.style.Fill({
                    color: color,
                    opacity: '0.05'
                }),
                text: new ol.style.Text({
                    font: '10px',
                    textAlign: 'center',
                    rotateWithView: true,
                    text: text,
                    fill: new ol.style.Fill({
                        color: 'rgba(255, 255, 255, 1)'
                    })
                })
            })
        }
        return style;
    },
    getCenter: function (id) {
        var cityId = id.substring(0, 2);
        var center = null;
        var url = '../../assets/newMap/data/mapdata/city/' + cityId + '.json';
        $.ajax({
            url: url,
            type: 'GET',
            async: false,
            success: function (data) {
                data.features.forEach(function (item) {
                    if (id == (item.properties.id + '00')) {
                        center = ol.proj.transform(item.properties.cp, 'EPSG:4326', 'EPSG:3857');
                        return;
                    }
                });
                if (center == null) {
                    center = ol.proj.transform(data.cp, 'EPSG:4326', 'EPSG:3857');
                }
            }
        })
        return center;
    },
    reset: function (inputData) {
        this.rqSource = null;
        inputData.currentMap = inputData.currentMap.replace(/\s+/g, "");
        this.inputData = inputData;
        this.vector.setSource(this.getSource(this.inputData));
        // var center = null;
        // if (inputData.city == '330100') {
        //     center = [13378925.93481097, 3535671.1803591126]
        // } else if(inputData.city == '530100') {
        //     center = [11448432.348440556, 2861190.842770717];
        // } else {
        //     center = this.getCenter(inputData.city);
        // }
        // map.getView().animate({
        //     center: center,
        //     duration: 2000
        // });
        // map.getView().setCenter(center);
        // map.getView().setZoom(10);
        heatmap.map.getOverlays().clear();
    },
    setRqCenter: function (community, inputData) {
        heatmap.isClick = true;
        var center = [community.lng, community.lat];
        this.inputData = inputData;
        heatmap.rqInfoId = community.communityId;
        heatmap.rqInfoCount = community.count;
        heatmap.rqInfoName = community.communityName;
        heatmap.map.getView().setCenter(center);
        var zoom = heatmap.map.getView().getZoom();
        if (zoom >= 18) {
            heatmap.map.getOverlays().clear();
            heatmap.vector.setVisible(false);
            heatmap.rqVector.setVisible(false);
            if (heatmap.rqInfoVector != null) {
                heatmap.map.removeLayer(heatmap.rqInfoVector);
            }
            heatmap.rqVector.setSource(new ol.source.Vector());
            heatmap.rqInfoVector = new ol.layer.Vector();
            heatmap.rqInfoVector.setSource(heatmap.getRqInfoSource())
            heatmap.map.addLayer(heatmap.rqInfoVector);
            heatmap.map.addInteraction(heatmap.selectPointerMove);
        } else {
            heatmap.map.getView().setZoom(18);
            heatmap.map.getOverlays().clear();
        }
    },
    getInputData: function (currentMap) {
        var communityName = $("#search").val(),
            city = $('#city').val(),
            district = $('#district').val(),
            risk = $('#risk').val(),
            startDateStart = $('#startDateStart').val(),
            startDateEnd = $('#startDateEnd').val(),
            buildArea = $('#buildArea').val(),
            customCode = $('#customCode').val(),
            customValue = $('#customValue').val(),
            loansDuration = $('#loansDuration').val(),
            inputData = {
                communityName: communityName,
                city: city,
                district: district,
                risk: risk,
                startDateStart: startDateStart,
                startDateEnd: startDateEnd,
                buildArea: buildArea,
                loansDuration: loansDuration,
                currentMap: currentMap,
                customCode: customCode,
                customValue: customValue
            };
        return inputData;
    },//楼栋覆盖物
    createDiv: function (paramsData) {
        var resultList = new Array();
        var tmpList = new Array();
        var resultList, topDiv, sj, lastSmall, oneSmall;
        paramsData.forEach(function (searchEstate) {
            var div = document.createElement("div");
            searchEstate.estateList.forEach(function (data, i) {
                //自定义楼栋覆盖物
                var smallDiv;
                if (i != 0) {
                    if (oneSmall) oneSmall.style.padding = "0 10px 0px 5px";
                    smallDiv = document.createElement('div');
                    smallDiv.appendChild(document.createTextNode(data.count + '笔'));
                    smallDiv.style.padding = "0 10px 0px 10px";
                    smallDiv.style.borderRadius = '8px';
                    smallDiv.style.marginLeft = '-10px';
                    smallDiv.style.lineHeight = '25px';
                    if (data.define == '中风险') {
                        smallDiv.style.backgroundColor = "#FF9800";
                    } else if (data.define == '低风险') {
                        smallDiv.style.backgroundColor = "#62CB31";
                    } else if (data.define == '高风险') {
                        smallDiv.style.backgroundColor = "#E51C23";
                    } else if (data.define == '亏损') {
                        smallDiv.style.backgroundColor = "#8B1818";
                    }
                    lastSmall = smallDiv;
                    topDiv.appendChild(smallDiv);
                } else {
                    if (lastSmall) lastSmall.style.padding = '0 10px 0px 10px';

                    div.style.position = "absolute";
                    div.style.color = "white";
                    div.style.opacity = '0.95';
                    div.style.display = 'flex';
                    div.style.whiteSpace = "nowrap";
                    div.style.MozUserSelect = "none";
                    div.style.fontSize = "12px";
                    div.style.cursor = "pointer";
                    div.style.height = "25px";
                    smallDiv = document.createElement('div');
                    smallDiv.appendChild(document.createTextNode(data.count + '笔'));
                    smallDiv.style.padding = "0 10px 0 5px";
                    smallDiv.style.borderRadius = "8px";
                    smallDiv.style.lineHeight = "25px";
                    div.appendChild(smallDiv);
                    sj = this._p = document.createElement("p");
                    if (data.define == '中风险') {
                        smallDiv.style.backgroundColor = "#FF9800";
                        sj.style.borderTop = "10px solid #FF9800";
                    } else if (data.define == '低风险') {
                        smallDiv.style.backgroundColor = "#62CB31";
                        sj.style.borderTop = "10px solid #62CB31";
                    } else if (data.define == '高风险') {
                        smallDiv.style.backgroundColor = "#E51C23";
                        sj.style.borderTop = "10px solid #E51C23";
                    } else if (data.define == '亏损') {
                        smallDiv.style.backgroundColor = "#8B1818";
                        sj.style.borderTop = "10px solid #8B1818";
                    }
                    sj.style.position = "absolute";
                    sj.style.width = 0;
                    sj.style.height = 0;
                    sj.style.borderLeft = "10px solid transparent";
                    sj.style.borderRight = "10px solid transparent";
                    sj.style.bottom = "-20px";
                    sj.style.left = '6px';
                    div.appendChild(sj);
                    oneSmall = smallDiv;
                    lastSmall = null;
                    topDiv = div;
                }
                $(topDiv).hover(function () {
                    $(this).css('z-index', 11);
                }, function () {
                    $(this).css('z-index', 'auto')
                });
                topDiv.onclick = function () {
                    var inputData = heatmap.inputData;
                    inputData.x=searchEstate.lng;
                    inputData.y= searchEstate.lat;
                    inputData.communityId=searchEstate.communityId;
                    var parentThat = this;
                    $.ajax({
                        url: "/map/mapBuildingData2",
                        type: "POST",
                        data: inputData,
                        success: function (data) {
                            if(data.result["mapDataStatus"]==false){
                                return
                            }
                            var mapDataList = data.result["mapDataList"];
                            $(parentThat).parent().siblings().children().children("div.row").css("display", "none");
                            $(parentThat).parent().siblings().children().css('zIndex', 'auto');
                            $(parentThat).css('zIndex', '11')
                            $(parentThat).children('div.row').toggle();
                            if ($(parentThat).children('div.row').length >= 1) return;
                            var listDiv = document.createElement("div");
                            listDiv.style.position = 'absolute';
                            listDiv.style.left = parentThat.offsetWidth + 14 + "px";
                            listDiv.style.color = '#6a6c6f';
                            listDiv.style.width = '400px';
                            listDiv.style.whiteSpace = 'normal';
                            listDiv.className = 'row';
                            var col = document.createElement("div");
                            var hpanel = document.createElement("div");
                            hpanel.className = 'hpanel';
                            var hpanelHead = document.createElement("div");
                            hpanelHead.className = 'panel-heading hbuilt';
                            hpanelHead.onclick = function (e) {
                                e.stopPropagation()
                            };
                            var panelTools = document.createElement('div');
                            panelTools.className = 'panel-tools';
                            var closebox = document.createElement('a');
                            var closeIcon = document.createElement('i');
                            closeIcon.className = 'fa fa-times';
                            closebox.appendChild(closeIcon);
                            closebox.className = 'closebox';
                            closebox.onclick = function () {
                                $(parentThat).children("div.row").css("display", "none");
                            };
                            panelTools.appendChild(closebox);
                            hpanelHead.appendChild(panelTools);
                            hpanelHead.appendChild(document.createTextNode(mapDataList[0].communityname));
                            var hpanelBody = document.createElement("div");
                            hpanelBody.className = 'panel-body no-padding';
                            hpanelBody.style.maxHeight = '190px';
                            hpanelBody.style.overflowY = 'auto';
                            var listGroup = document.createElement('ul');
                            listGroup.className = 'list-group';
                            var hpanelFoot = document.createElement('div');
                            hpanelFoot.className = 'panel-footer';
                            hpanelBody.appendChild(listGroup);
                            hpanel.appendChild(hpanelHead);
                            hpanel.appendChild(hpanelBody);
                            hpanel.appendChild(hpanelFoot);
                            col.appendChild(hpanel);
                            listDiv.appendChild(col);
                            parentThat.appendChild(listDiv);
                            mapDataList.forEach(function (data) {
                                var item = document.createElement('li');
                                item.className = 'list-group-item ';
                                var badge = document.createElement('span');
                                badge.className = 'badge badge-info';
                                badge.innerHTML = data.cltv + '%';
                                item.appendChild(badge);
                                if (data.define == '中风险') {
                                    badge.style.backgroundColor = "#FF9800";
                                } else if (data.define == '低风险') {
                                    badge.style.backgroundColor = "#62CB31";
                                } else if (data.define == '高风险') {
                                    badge.style.backgroundColor = "#E51C23";
                                } else if (data.define == '亏损') {
                                    badge.style.backgroundColor = "#8B1818";
                                }
                                item.appendChild(document.createTextNode(data.sourceaddress));
                                item.onclick = function () {
                                    var warningType = heatmap.inputData.warningType;
                                    var href = "";
                                    if( !warningType){
                                        href = window.location.origin + "/estate/mapShow/" + data.id;
                                    }else if(warningType == '1'){
                                        href = location.origin + '/riskWarning/priceFluctuationsRatioWarningShow?id=' + data.id;
                                    }else if(warningType == '14'){
                                        href = location.origin + '/riskWarning/effectiveMaturityWarningShow?id=' + data.id;
                                    }
                                    window.open(href);
                                };
                                listGroup.appendChild(item);
                            });
                            var listLength = listGroup.children.length;
                            hpanelFoot.innerHTML = '共 ' + listLength + ' 笔';
                        }
                    });
                };
            });
            if (searchEstate.estateList.length > 0) {
                tmpList = new Array();
                tmpList[0] = topDiv;
                tmpList[1] = [searchEstate.lng, searchEstate.lat];
                resultList.push(tmpList);
            }
        });
        return resultList;
    },
    createRightDiv: function (inputData, hourseCount) {
        var div = this._div = document.createElement("div");
        var img = document.createElement('img');
        img.src = '/assets/accountLogo/zhoubian.png';
        div.style.position = "absolute";
        div.style.cursor = 'pointer';
        div.style.zIndex = '1';
        var message = document.createElement('div');
        message.style.position = 'absolute';
        message.style.border = '1px solid rgb(98, 203, 49)';
        message.style.background = '#fff';
        message.style.borderRadius = '6px';
        message.style.width = '230px';
        message.style.height = '50px';
        message.style.top = '-60px';
        message.style.left = '-98px';
        message.style.textAlign = 'center';
        var header = document.createElement('h5');
        header.innerHTML = heatmap.rqInfoName;
        header.style.fontWeight = 'bold';
        header.style.color = '#62cb31';
        message.appendChild(header);
        var body = document.createElement('p');
        body.innerHTML = '已押总量:<strong> ' + heatmap.rqInfoCount + '</strong>&nbsp;&nbsp;&nbsp;总户数:<strong> ' + hourseCount + '</strong>';
        message.appendChild(body);
        var sj = this._p = document.createElement("p");
        sj.style.position = "absolute";
        sj.style.width = 0;
        sj.style.height = 0;
        sj.style.borderLeft = "10px solid transparent";
        sj.style.borderRight = "10px solid transparent";
        sj.style.bottom = "-20px";
        sj.style.left = '105px';
        sj.style.borderTop = "10px solid #62cb31";
        message.appendChild(sj);
        div.appendChild(message);
        div.appendChild(img);
        message.onclick = function () {
            var warningType = heatmap.inputData.warningType;
            var href = "";
            if( !warningType ){
                href = location.origin + '/estate/index?communityId=' + heatmap.rqInfoId;
            }else if(warningType == '1'){
                href = location.origin + '/riskWarning/priceFluctuationsRatioWarning?communityId=' + heatmap.rqInfoId;
            }else if(warningType == '14'){
                href = location.origin + '/riskWarning/effectiveMaturityWarning?communityId=' + heatmap.rqInfoId;
            }else if(warningType == '7'){
                href = location.origin + '/riskWarning/concentrationWarningShow?id=' + heatmap.rqInfoId;
            }else if(warningType == '15'){
                href = location.origin + '/riskWarning/buildingScoreWarningShow?id=' + heatmap.rqInfoId + "&city=" + heatmap.zoneNumber;
            }else if(warningType == '10'){
                href = location.origin + '/riskWarning/collateralCoverageRateWarningShow?id=' + heatmap.rqInfoId;
            }

            window.open(href);
        };
        img.onclick = function () {
            $(this).siblings('div').toggle();
        };
        return div;
    },
    hiddenOverly: function () {
        var eleOverlys = $('.ol-overlay-container.ol-selectable');
        for (var i = 0; i < eleOverlys.length; i++) {
            var div = eleOverlys[i];
            var dis = div.style.display;
            if (dis != 'none') {
                div.style.display = 'none';
            }
        }
    },
    showOverly: function () {
        var eleOverlys = $('.ol-overlay-container.ol-selectable');
        for (var i = 0; i < eleOverlys.length; i++) {
            var div = eleOverlys[i];
            var dis = div.style.display;
            if (dis != 'block') {
                div.style.display = 'block';
            }
        }
    },
    referrerInit: function (inputData) {
        var city = inputData["city"];
        var district = inputData['district'];
        var communityId = inputData['communityId'];
        this.init();
        if (city == '' || city == null) {
            return;
        } else {
            if (district == null || district == '' || district == -1) {
                $("#city").val(city);
                $("#city").change();
            } else {
                if (communityId == null || communityId == '') {
                    $("#city").val(city);
                    this.getArea();
                    $("#district").val(district);
                    $("#district").change();
                } else {
                    heatmap.map.getView().setZoom(18);
                    inputData.district = '-1';
                    heatmap.vector.setSource(heatmap.getRqSource(inputData))
                }
            }
        }
    },
    getColorForId: function (id, size) {
        var color = 'rgba(76, 160, 101, 0.9)';
        switch (id) {
            case 'province': {
                color = 'rgba(76, 160, 101, 0.9)';
            }
                break;
            case 'city': {
                if (size > 700) {
                    color = "#26b095";
                } else if (size > 500) {
                    color = "#33c3a7"
                } else if (size > 300) {
                    color = "#4cdcc0";
                } else {
                    color = "#79ecd6";
                }
            }
                break;
            case 'county': {
                if (size > 700) {
                    color = "#26b095";
                } else if (size > 500) {
                    color = "#33c3a7"
                } else if (size > 300) {
                    color = "#4cdcc0";
                } else {
                    color = "#79ecd6";
                }
            }
                break;
            case 'rq': {
                if (size > 15) {
                    color = "#26b095";
                } else if (size > 10) {
                    color = "#33c3a7"
                } else if (size > 5) {
                    color = "#4cdcc0";
                } else {
                    color = "#79ecd6";
                }
            }
                break;
        }
        return color;
    },
    getArea: function () {
        $("#district option").remove();
        var city = $("#city").val()
        $("#district").append("<option value='-1' >行政区</option>")
        if (city == '-1') {
            return
        }
        $.ajax({
            url: "/estate/districtList",
            type: "POST",
            data: {'city': city},
            success: function (result) {
                for (var i = 0; i < result.districtList.length; i++) {
                    $("#district").append("<option value=" + result.districtList[i].zoneNumber + ">" + result.districtList[i].name + "</option>")
                }
            }
        });
    },
    removeFeature: function (vector) {
        vector.getSource().forEachFeature(function (feature) {
            if (feature.get('info') == 'rqBound') {
                vector.getSource().removeFeature(feature)
            }
        })
    }
}